package spring;

/**
 * @ProjectName: Spring
 * @Package: spring
 * @ClassName: AopConfigUtils
 * @Author: zxh
 * @Description:
 * @Date: 2022/3/19 15:44
 * @Version: 1.0
 */
public class AopConfigUtils {

    public static final String AUTO_PROXY_CREATOR_BEAN_NAME = "abstractAutoProxyCreator";

    public static BeanDefinition registerAspectJAnnotationAutoProxyCreatorIfNecessary(DefaultListableBeanFactory registry) {

        return registerOrEscalateApcAsRequired(AbstractAutoProxyCreator.class, registry);

    }

    private static BeanDefinition registerOrEscalateApcAsRequired(Class cls, BeanDefinitionRegistry registry) {

        BeanDefinition beanDefinition = new BeanDefinition();
        beanDefinition.setScope("singleton");
        beanDefinition.setClazz(cls);
        registry.registerBeanDefinition(AUTO_PROXY_CREATOR_BEAN_NAME,beanDefinition);
        return beanDefinition;

    }
}
